package com.zzw.zim.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzw.zim.system.entitys.SysUserEntity;
import com.zzw.zim.system.dao.SysUserDao;
import com.zzw.zim.system.dto.SysUserDTO;
import com.zzw.zim.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;


@Service
public class UserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {

    @Resource
    @Qualifier("password")
    private PasswordEncoder passwordEncoder;

    @Override
    public Boolean addUser(SysUserDTO userDTO) {
        String encode = passwordEncoder.encode(userDTO.getPassword());
        userDTO.setPassword(encode);
        SysUserEntity user = new SysUserEntity();
        BeanUtil.copyProperties(userDTO,user);
        user.setUserType(1);
        baseMapper.insert(user);
        return true;
    }

    @Override
    public Boolean removeUser(String userId) {
        baseMapper.updateByUserId(userId);
        return true;
    }

}
